//
//  DaishouExpressViewController.m
//  TengyunStation
//
//  Created by Johnny on 15/10/22.
//  Copyright © 2015年 xingrong. All rights reserved.
//

#import "DaishouExpressViewController.h"
#import "DaishouDetailViewController.h"
#import "DaishouView.h"
#import "Singleton.h"

@interface DaishouExpressViewController ()<DaishouViewDelegate,DaishouDetailViewControllerDelegate> {
    DaishouView *_daishouView;
    DaishouView *_yijieshouView;
    Daishou *_currentDaishou;
}

@end

@implementation DaishouExpressViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"待收快件";
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self handelNetWorkMethod];
    _multipleTabView.tabArray = @[@"待处理",@"已处理"];
    float height = [UIScreen mainScreen].bounds.size.height - 44 - 64;
    _bgScrollView.contentSize = CGSizeMake(320 * 2, height);
    for (int i = 0; i < 2; i ++) {
        DaishouView *view = [[DaishouView alloc] initWithFrame:CGRectMake(320 * i, 0, 320, height)];
        view.daishouViewDelegate = self;
        if (i == 0) {
            view.type = @"1";
            _daishouView = view;
        } else {
            view.type = @"2";
            _yijieshouView = view;
        }
        [_bgScrollView addSubview:view];
    }
}

#pragma mark DaishouViewDelegate
- (void)didFinishSelected:(Daishou *)daishou DaishouView:(DaishouView *)view {
    _currentDaishou = daishou;
    DaishouDetailViewController *daishouDVC = [[DaishouDetailViewController alloc] initWithNibName:@"DaishouDetailViewController" bundle:nil];
    daishouDVC.daishou = daishou;
    daishouDVC.delegate = self;
    [self.navigationController pushViewController:daishouDVC animated:YES];
}

#pragma mark DaishouDetailViewControllerDelegate
- (void)daishouDetailVCIsRefuse:(BOOL)isRefuse {
    [Singleton shareInstance].statisticsCount.waitExpressesCount --;
    [_daishouView.daishouExpressList removeObject:_currentDaishou];
    [_daishouView reloadTalbeView];
    [_yijieshouView reloadDaishouData];
}

#pragma mark MultipleTabViewDelegate
- (void)buttonClickIndex:(NSInteger)currentIndex {
    [_bgScrollView setContentOffset:CGPointMake(320 * currentIndex, 0) animated:YES];
    if (currentIndex == 0) {
        _bgScrollView.bounces = NO;
    } else {
        _bgScrollView.bounces = YES;
    }
}

#pragma mark UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    NSInteger index = (NSInteger)scrollView.contentOffset.x/320;
    _multipleTabView.index = index;
    if (index == 0) {
        _bgScrollView.bounces = NO;
    } else {
        _bgScrollView.bounces = YES;
    }
}


@end
